package resourceModule.component;

import java.util.ArrayList;
import java.util.List;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IAuthorityResourceInfo;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.SaturnAuthorityManager;

public class QueryResourceWithCondition extends DefaultComponent {
	public void execute(IParameterContext parameterContext) throws Exception {
		String resourceName = (String) parameterContext.getParameterValue(0);
		
		List<IAuthorityResourceInfo> allResourceList = SaturnAuthorityManager
		.getInstance().getAllResources();
		
		if(resourceName==null||"".equals(resourceName)){
			parameterContext.setParameter(1, allResourceList);
			
			
		}else{
			List<IAuthorityResourceInfo> resourceList = new ArrayList<IAuthorityResourceInfo>();
			
			for (IAuthorityResourceInfo resourceInfo : allResourceList) {
				
				if(resourceInfo.getName().contains(resourceName)){
					resourceList.add(resourceInfo);
				}
			}
			parameterContext.setParameter(1, resourceList);
		}
	}
}